<template>
  <div class="empty">
<!--     <el-tree :data="value.models" :props="defaultProps" :expand-on-click-node="false">
      <span class="custom-tree-node" slot-scope="{ node, data }">
        <span>{{ node.label }}</span>
        <span style="float: right;">
          <el-button type="text" size="mini" @click="() => handleRemove(node, data)">
            删除
          </el-button>
        </span>
      </span>
    </el-tree> -->
  </div>
</template>
<script type="text/javascript">
export default {
  components: {
    //empty
  },
  props: {
    value: [Array, Object],

  },
  data() {
    return {
      defaultProps: { // 树相关属性设置
        children: "fields",
        label: "title"
      }
    }
  },
  /**
   * 计算属性
   * @type {Object}
   */
  computed: {
    models: function(argument) {
      let models = this.value.models;
      let data = [];
      //循环遍历设置
      for (let i in models) {
        let item = models[i];
        let label = {
          label: item.title,
          children: []
        }
        let fields = item.fields;
        for (let _i in fields) {
          let _item = fields[_i];
          let _label = {
            label: _item.title
          }
          label.children.push(_label);
        }
        data.push(label);
      }
      return data;
    }
  },
  /**
   * 数据监听
   * @type {Object}
   */
  watch: {

  },
  /**
   * 页面加载执行
   * @return {[type]} [description]
   */
  mounted() {

  },
  /**
   * 页面方法
   * @type {Object}
   */
  methods: {
    handleNodeClick(e) {

    },
    handleRemove(node, data) {
      console.log(node, data);
      const parent = node.parent;
      const children = parent.data.fields || parent.data;

      const index = children.findIndex(d => d.$treeNodeId === data.$treeNodeId);

      children.splice(index, 1);
    }
  }
}

</script>
<style type="text/css">
    .custom-tree-node {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 14px;
    padding-right: 8px;
  }
</style>
